import axios from 'axios';

const instance = axios.create({
    baseURL: 'http://kumanxuan1.f3322.net:8360/admin'
});

// 请求前拦截
instance.interceptors.request.use((config) => {
    // let token = localStorage.getItem('token')
    // if(token){
    //     // 我们只是需要携带一个请求头的属性传递过去
    //     config.headers = config.headers || {}
    //     config.headers['Authorization'] = token
    // }
    let token = localStorage.getItem('token')
    if (token) {
        config.headers = config.headers || {}
        config.headers['X-Nideshop-Token'] = token
    }
    return config;
}, err => {
    return Promise.reject(err);
})

// 响应拦截
instance.interceptors.response.use((result) => {
    return result.data;
}, err => {
    return Promise.reject(err);
})

export default instance